import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  server: {
    port: 5173,
    host: true,
    proxy: {
      '/api': {
        target: 'http://localhost:5000',
        changeOrigin: true,
        secure: false,
      },
    },
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets',
    sourcemap: false,
    rollupOptions: {
      output: {
        manualChunks: {
          'vue-vendor': ['vue', 'vue-router', 'pinia'],
          'ui-vendor': ['@headlessui/vue', '@heroicons/vue'],
          'home': ['./src/views/Home.vue'],
          'browse': ['./src/views/Browse.vue'],
          'article': ['./src/views/Article.vue'],
          'favorites': ['./src/views/Favorites.vue'],
          'search': ['./src/views/Search.vue'],
          'settings': ['./src/views/Settings.vue'],
          'api-services': ['./src/services/api.js', './src/services/articleService.js'],
          'utils': ['./src/utils/logger.js', './src/utils/error-handler.js'],
        },
      },
    },
  },
  optimizeDeps: {
    include: ['vue', 'vue-router', 'pinia', 'axios'],
  },
})
